﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HsTec.Mobile.Green.SqlServerDAL;

public partial class BaseData_ProjectManage : Baimasoft.Web.UI.PageManagerTop
{
    Project MyPj = new Project();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindControlEvent();
        this.HiddenID.Value = "";
        if (!this.IsPostBack)
        {
            try
            {
                Indicator.Text = Request.QueryString["sIndicator"].ToString();
            }
            catch
            {
            }
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            this.SDT.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
            this.EDT.Text = DateTime.Now.ToString("yyyy-MM-dd");
            this.BindGridViewData();//绑定GridView,为删除服务
        }
    }

    protected override void BindGridViewData()
    {

        this.DataSource = MyPj .GetProjectInfos (GetSearchString());

        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();

    }

    protected override void Delete(string ids)
    {
        try
        {
            int iback = MyPj.DeleteProjectInfo(ids);
            if (iback < 1)
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "没有可删除的数据!");
                return;
            }
            else
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "删除成功!");
                return;
            }
        }
        catch
        {
            Baimasoft.Web.UI.Message.AlertMsg(this, "删除失败!");
        }
    }


    protected override string GetSearchString()
    {
        string searchStr = "(1=1)";

        if (this.txtProjectName.Text.Trim().Length > 0)
        {
            searchStr += " and  project_name like '%" + this.txtProjectName.Text + "%' ";
        }

        if (txtproject_code.Text.ToString ().Trim () != "")
        {
            searchStr += " and project_code ='" + txtproject_code.Text.ToString().Trim() + "' ";
        }

        if (txtproject_level.Text.ToString().Trim() != "")
        {
            searchStr += " and project_level ='" + txtproject_level.Text.ToString().Trim() + "' ";
        }

        if (this.SDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),project_createdate,120) >= '" + this.SDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),project_createdate,120) >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }

        if (this.EDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),project_createdate,120) <= '" + this.EDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),project_createdate,120) <= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }

        return searchStr;
    }
}
